/* 
 * File:   main.cpp
 * Author: monkey
 *
 * Created on November 17, 2011, 2:11 PM
 */

#include <cstdlib>
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include "dbhelper.h"
#include "timer.h"
#include <string>
#include <time.h>

using namespace std;

/*
 * 
 */
int main(int argc, char** argv) {
    dbhelper *db = new dbhelper();
    if (db->connect("127.0.0.1", "root", "sa", "apps")) {
        if( db->setuft8())
        cout << "Connection successful!" << endl;
        
        db->query("insert into user values(null,'admin','sa','Nguyễn Sỹ Quân','1990-06-19',1)");
        //db->query(query);
        char * query = "select * from user";
        //char* query = "insert into user values(null,'test7','sa','Nguyễn Sỹ Quân','1990-06-19',1)";
        db->query(query);

        int row, col;
        char ***result = db->parse_res(&row, &col, NULL);

        if (result) {
            for (int i = 0; i < row; i++) {
                for (int j = 0; j < col; j++) {
                    cout << result[i][j] << " | ";
                }
                cout << endl;
            }
        } else {
            cout << "Query is not return a result!";
        }

    } else {
        cout << "Connection failed!" << endl;
    }
    db->close();

    
    timer *time_ctrl;
    time_ctrl = new timer();
    
    cout<<time_ctrl->get_current_date();


    return 0;
}

